/*
 * @Author: xgz
 * @Date: 2019-11-14 10:02:13
 * @Last Modified by: //此处填修改人名字
 * @Last Modified time: 2019-11-14 11:33:47
 */
<template>
  <section class="carTypeConfig">
    <el-dialog v-dialogDrag
      title="卡券选择"
      :visible.sync="curPopupsVisible"
      width="1000px"
      center
      @close="sendCode"
      :close-on-click-modal="false"
      :append-to-body="true"
      ref="dialogMultipleTable"
    >
      <dialogHeader
        slot="title"
        :title="'卡券选择'"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <one-table-template
        ref="multipleTable"
        :dynamicButtons="tableButtons"
        :dynamicComponents="tableComponents"
        :dynamicApiConfig="apiConfig"
        :dynamicTableCols="tableCols"
        :dynamicFormFields="formField"
        :dynamicIsShowSelect="isMul"
        :key="popupsTableKey"
      />
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { valueObjectMixins } from "@/components/mixins/valueObjectMixins";
import { crmApis } from "@/api/apiList/crm";
import OneTableTemplate from "@/components/crm/commonComponents/crmPopupsOneTable";
export default {
  // 组件混入对象：{data[listQuery] methods[queryTable]}
  mixins: [oneTableWithViewTemplateMixins, valueObjectMixins],
  components: {
    OneTableTemplate,
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 网格查询API配置对象
      apiConfig: crmApis.crmBuCardticketQueryFindAll,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(1),
          text: "查询",
          position: "top"
        },
        {
          compKey: "btnKey2",
          type: "primary",
          size: "small",
          clickEvent: () => this.sendCode("couponId","couponName"),
          text: "确认",
          position: "bottom"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置",
          position: "top"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        // 显示组件
        {
          compKey: "compKey1",
          labelName: "卡券名称",
          codeField: "couponName",
          component: () => import("@/components/org/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey2",
          labelName: "卡券类型",
          codeField: "couponCategory",
          lookuptype: "LX825",
          component: () => import("@/components/org/LookupValue"),
          type: "dropdownList",
          isMust: true,
          isMul: false
        },
        {
          compKey: "compKey4",
          labelName: "领取日期",
          codeField: "receivedBeginDay,receivedEndDay",
          component: () => import("@/components/crm/Time/crmdtDatePicker"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey5",
          labelName: "是否启用",
          codeField: "isEnable",
          disabled:true,
          component: () => import("@/components/crm/Select/crmIsEnable"),
          type: "dropdownList",
          isMust: true,
          isMul:false,
        }
      ],
      // 动态生成网格列
      tableCols: [
        { prop: "couponCategoryName", label: "卡券类型", width: 100, align: "center" },
        { prop: "couponCode", label: "卡券编码", width: 150, align: "center" },
        { prop: "couponName", label: "卡券名称", width: 150, align: "center" },
        { prop: "receivedBeginDay", label: "领取开始日期", width: 150, align: "center" },
        { prop: "receivedEndDay", label: "领取结束日期", width: 150, align: "center" },
        { prop: "effectivTypeName", label: "有效期类型", width: 100, align: "center" },
        { prop: "effectiveBeginDay", label: "有效开始日期", width: 150, align: "center" },
        { prop: "effectiveEndDay", label: "有效结束日期", width: 150, align: "center" },
        { prop: "effectiveDays", label: "有效天数", width: 100, align: "center" },
        { prop: "isEnableName", label: "是否启用", width: 80, align: "center" },
        { prop: "couponId", label: "卡券ID", width: null, align: "center",hidden: true}
      ],
      //表单查询数据（查询条件）
      formField: {
        isEnable:"1",
        couponName:"",
        couponCategory:"",
        receivedBeginDay: "",
        receivedEndDay: ""
      },
      handleTableRowData: {
        value: "couponId",
        text: "couponName"
      }
    };
  },
  methods:{
    sendCode(arrayCodeField, arrayTextField) {
      // 获取嵌套组件的选中的值
      debugger
      const that = this.$refs.multipleTable
      const selectData = []
      if(this.isMul==true)
      {
        selectData = this.$refs.multipleTable.selection;
      }else{
        selectData.push(this.$refs.multipleTable.currentRow);
      }
      if (selectData&&selectData.length>0) {
        let tmpCodeField = arrayCodeField
        let tmpTextField = arrayTextField
        this.modelCode = this.$utils.getArrayFromJsonArray(selectData, tmpCodeField)
        this.modelText = this.$utils.getArrayFromJsonArray(selectData, tmpTextField)
      } else {
        this.modelCode = []
        this.modelText = []
      }
      var code = typeof (this.modelCode) === 'string' ? this.modelCode : this.modelCode.join(',')
      var text = typeof (this.modelText) === 'string' ? this.modelText : this.modelText.join(',')
      this.$emit('changeCode', code, text, this.codeField, this.comType, this.popupsKey, this.textField, this.otherField, selectData)
    }

  }
};
</script>
